package com.comment.project.socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
 * @author liupenghui
 * @date 2018/7/20
 * @desc： socket服务端
 */
public class Server {
    private static int count;
    private static Socket socket;

    public static void main(String[] args) throws IOException {
        // 创建服务端 端口号9527
        ServerSocket serverSocket = new ServerSocket(9527);
        System.out.println("服务器已启动,等待客户连接...");
        while(true){
            // 服务端阻塞式监听客户端连接请求
            // 接收到连接请求，则创建一个socket实例，与客户端通信
            socket = serverSocket.accept();

            ServerThread st = new ServerThread(socket);
            st.start();
            System.out.println("这是第"+(count++)+"位用户");
            System.out.println("此用户的IP地址为"+socket.getInetAddress().getHostAddress());
        }
    }
}
